/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cc.view;

import cc.controller.ConverterFacade;
import cc.model.CurrencyDTO;
import cc.model.CurrencyRate2;
import javax.inject.Named;
import javax.enterprise.context.ConversationScoped;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Conversation;
import javax.inject.Inject;

/**
 *
 * @author zno
 */
@Named("conversionManager")
@ApplicationScoped
public class ConversionManager implements Serializable {
    
    private static final long serialVersionUID = 8094890458059358L;
    @EJB
    private ConverterFacade converterFecade;
    private String fromCurrency;
    private String toCurrency;
    private Exception transactionFailure;
    
    
    private float amount;
    private float amountConverted;
    
    
    
    
    
    
    
    
    public void convert(){
        System.err.println("Conversion invoked From: "+fromCurrency+" to "+toCurrency +" the amount of "+amount);
        amountConverted=101;
        try {
            
            transactionFailure = null;
            amountConverted=converterFecade.convert(fromCurrency,toCurrency, this.amount);
        }catch (Exception e){
            
            handleException(e);
            
        }
        
        
        
        
         
        
        
        
    
        
    }

    public String getFromCurrency() {
        return fromCurrency;
    }

    public void setFromCurrency(String fromCurrency) {
        this.fromCurrency = fromCurrency;
    }

    public String getToCurrency() {
        return toCurrency;
    }

    public void setToCurrency(String toCurrency) {
        this.toCurrency = toCurrency;
    }

    

    
    
    
    public float getAmount() {
        return amount;
    }

    public void setAmount(float amount) {
        this.amount = amount;
    }

    

    

    
    
    
    
    
    private void handleException(Exception e) {
        
        e.printStackTrace(System.err);
        transactionFailure = e;
    }

    /**
     * Returns <code>false</code> if the latest transaction failed, otherwise <code>true</code>.
     */
    public boolean getSuccess() {
        //return transactionFailure == null;
        return true;
    }

    /**
     * Returns the latest thrown exception.
     */
    public Exception getException() {
        return transactionFailure;
    }

    public float getAmountConverted() {
        return amountConverted;
    }

    public void setAmountConverted(float amountConverted) {
        this.amountConverted = amountConverted;
    }
    
    
    
    
}
